package com.easymin.daijia.server.task;

import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

/**
 * @author zhyu
 * @date 2020/1/6 15:59
 */
public class MyTask extends TimerTask {

    private final Sign sign;
    private Integer taskName;
    private Map<Integer, Timer> taskMaps;

    public MyTask(Sign sign, Integer taskName, Map<Integer, Timer> taskMaps) {
        this.sign = sign;
        this.taskName = taskName;
        this.taskMaps = taskMaps;
    }

    @Override
    public void run() {
        try {
            Thread.sleep(5000);
            System.out.println("thread " + taskName + " print is working !");
            if (sign.isSuccess() && null != taskMaps) {
                taskMaps.remove(taskName).cancel();
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
